<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Route;

class News extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'summary' => $this->summary,
            'body' => $this->when(Route::currentRouteName() == 'news.show' || Route::currentRouteName() == 'news.edit', function () {
                return $this->body;
            }),
            'view_counts' => $this->view_counts,
            'comment_counts' => $this->comment_counts,
            'thumb_up_counts' => $this->thumb_up_counts,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at
        ];
    }
}
